﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;

namespace TjZheng.EasyUI
{
    /// <summary>
    /// EasyUI验证类型
    /// </summary>
    public class ValidType
    {
        /// <summary>
        /// 验证长度
        /// </summary>
        /// <param name="minLength"></param>
        /// <param name="maxLength"></param>
        /// <returns></returns>
        public static string Length(int minLength, int maxLength)
        {
            return string.Format("'length[{0},{1}]'", minLength, maxLength);
        }
        /// <summary>
        /// 验证长度
        /// </summary>
        /// <param name="maxLength"></param>
        /// <returns></returns>
        public static string Length(int maxLength)
        {
            return Length(0, maxLength); ;
        }

        /// <summary>
        /// 验证正则表达式
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static string Regex(string expression)
        {
            if (expression.IsNull())
            {
                return string.Empty;
            }
            expression = expression.Replace(@"\", @"\\\\");//easyui bug，正则表达式的\会被替换掉，四个\只剩下一个
            return string.Format("'validExpression[\"{0}\"]'", expression);
        }

        /// <summary>
        /// 判断对对应选择器的值是否相等
        /// </summary>
        /// <param name="selector">选择器</param>
        /// <returns></returns>
        public static string Equal(string selector)
        {
            return string.Format("'validEqual[\"{0}\"]'", selector);
        }
    }
}
